package com.javaenzk.wfx.manager.service.impl;


import com.javaenzk.wfx.manager.dao.ShoppingMapper;
import com.javaenzk.wfx.manager.po.Tbshoppingcar;
import com.javaenzk.wfx.manager.service.ISHoppingCartService;
import com.javaenzk.wfx.manager.util.ResultJson;
import com.javaenzk.wfx.manager.vo.JsonResultVO;
import com.javaenzk.wfx.manager.vo.MerchantInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ShoppingService implements ISHoppingCartService {

    @Resource
    private ShoppingMapper shoppingMapper;

    /**
     * 方法体的名称要遵循restful的要求,方法一定要有返回值
     * @param tbShoppingCar
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @Override
    public JsonResultVO addShopping(@RequestBody Tbshoppingcar tbShoppingCar) {

        JsonResultVO jsonResultVO = new JsonResultVO();

//        if (1==1)
//        {
//            throw new NullPointerException("故意出错");
//        }

        try {
            shoppingMapper.addShopping(tbShoppingCar);
            jsonResultVO.setCode(1);

        }catch (Exception e){
            jsonResultVO.setCode(0);
        }
        return jsonResultVO;
    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @Override
    public List<MerchantInfo> queryShoppingList() {
        return shoppingMapper.queryShoppingList();
    }
}
